package com.tb.shoop.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.tb.v1.api.shoop.ISpReportService;
import com.tb.v1.result.ResultJson;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author: tangBin
 * @Date: 2020/7/29 0029 17:59
 * @Description:
 */
@RestController
@RequestMapping("v1")
public class SpReportController extends BaseController {
    @Reference
    private ISpReportService spReportService;

    /**
     * @return com.tb.v1.result.ResultJson<java.lang.Object>
     * @Author tangBin
     * @Description echarts 报表数据展示
     * @Date 2020/7/29 0029 18:01
     * @Param []
     **/
    @RequestMapping("getReport")
    public ResultJson<Object> getReports() {
        Map result = new HashMap();
        Map areaMap = new HashMap();
        List<String> areaList = spReportService.getReportArea();
        areaMap.put("data", areaList);
        result.put("legend", areaMap);

        List<Map> yAxisList = new ArrayList<>();
        Map yAxisMap = new HashMap();
        yAxisMap.put("type", "value");
        yAxisList.add(yAxisMap);
        result.put("yAxis", yAxisList);

        List<Map> xAxisList = new ArrayList<>();
        Map xAxisMap = new HashMap();
        List<String> dateList = spReportService.getReportDate();
        xAxisMap.put("data", dateList);
        xAxisList.add(xAxisMap);
        result.put("xAxis", xAxisList);

        List<Map> seriesList = new ArrayList<>();
        for (String str : areaList) {
            Map seriesMap = new HashMap();
            Map areaStyleMap = new HashMap();
            Map normalMap = new HashMap();
            seriesMap.put("name", str);
            seriesMap.put("type", "line");
            seriesMap.put("stack", "总量");
            areaStyleMap.put("normal", normalMap);
            seriesMap.put("areaStyle", areaStyleMap);
            List<Integer> sumList = spReportService.getReportSum(str);
            seriesMap.put("data", sumList);
            seriesList.add(seriesMap);
        }
        result.put("series", seriesList);
        return toResultModel("200", "成功", result);
    }
}
